public class JobListController {

	private String searchTerm;
	private List<SFDC_Position__c> positionList;
	private String NONE = '--None--';
	private String status = NONE;
	private String division = NONE;
	private String ptype = NONE;
	
	public PageReference loadTestData() {
		TestData.MakeData();
		return null;

	}
	public void setType(String value) {
		if (value == NONE) {
			value = '';
		}
		ptype = value;
	}
	public String getType() {
		return ptype;
	}
	public void setStatus(String value) {
		if (value == NONE) {
			value = '';
		} 
		status = value; 
	}
	public String getStatus() {	return status; }
	public void setDivision(String value) {
		if (value == 'Customer Service') {
			value += '/Customer Support'; 
		} else if (value == NONE) {
			value = '';
		}
		division = value; 
	}
	public String getDivision() { return division; }
	

	public List<SelectOption> getTypeItems() {
		List<SelectOption> options = new List<SelectOption>();
		options.add(new SelectOption('--None--', '--None--'));
		options.add(new SelectOption('Full Time Regular', 'Full Time Regular'));
		options.add(new SelectOption('Part Time', 'Part Time'));
		options.add(new SelectOption('Internship', 'Internship'));
		return options;
	}
	public List<SelectOption> getDivisionItems() {
		List<SelectOption> options = new List<SelectOption>();
		options.add(new SelectOption('--None--', '--None--'));
		options.add(new SelectOption('Administration', 'Administration'));
		options.add(new SelectOption('Customer Service', 'Customer Service'));
		options.add(new SelectOption('Facilities', 'Facilities'));
		options.add(new SelectOption('Finance', 'Finance'));
		options.add(new SelectOption('Human Resources', 'Human Resources'));
		options.add(new SelectOption('IT/MS', 'IT/MS'));
		return options;
	}
	public List<SelectOption> getStatusItems() {
		List<SelectOption> options = new List<SelectOption>();
		options.add(new SelectOption('--None--', '--None--'));
		options.add(new SelectOption('1 - New', '1 - New'));
		options.add(new SelectOption('2 - Approving', '2 - Approving'));
		options.add(new SelectOption('3 - Open', '3 - Open'));
		options.add(new SelectOption('X - Closed Cancelled', 'X - Closed Cancelled'));
		options.add(new SelectOption('X - Closed Filled', 'X - Closed Filled'));
		options.add(new SelectOption('X - Closed Not Approved', 'X - Closed Not Approved'));
		return options;
	}
	public JobListController() {
		positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c];
	}
	public String getSearchTerm() {
		return searchTerm;
	}
	public void setSearchTerm(String value) {
		if (value.length() > 0) {
			searchTerm = value;
		} else {
			searchTerm = '';
		}
	}
	/*
	    |  search  |  type  |  division  |  status  |
	    ---------------------------------------------
	    | z   0     |   0    |     0      |    0     |  ''
	    ---------------------------------------------
	    | z   X     |   0    |     0      |    0     |  (st like )
	    ---------------------------------------------
	    | z   X     |   X    |     0      |    0     |  (st like ) and (t =)
	    ---------------------------------------------
	    | z   X     |   0    |     X      |    0     |  (st like) and (d =)
	    ---------------------------------------------
	    | z   X     |   X    |     X      |    0     |  (st like) and (t =) and (d =)
	    ---------------------------------------------
	    | z   X     |   0    |     0      |    X     |  (st like) and (s =)
	    ---------------------------------------------
	    | z   X     |   X    |     0      |    X     |  (st like) and (t =) and (s =)
	    ---------------------------------------------
	    | z   X     |   X    |     X      |    X     |  (st like) and (t =) and (d = ) and (s =)
	    ---------------------------------------------
	    | z   X     |   0    |     X      |    X     |  (st like) and (d =) and (s =)
	    ---------------------------------------------
	    | z   0     |   X    |     0      |    0     |  (t =)
	    ---------------------------------------------
	    | z   0     |   X    |     X      |    0     |  (t =) and (d =)
	    ---------------------------------------------
	    | z   0     |   X    |     0      |    X     |  (t =) and (s =)
	    ---------------------------------------------
	    | z   0     |   X    |     X      |    X     |  (t =) and (s =) and (d =)
	    ---------------------------------------------
	    | z   0     |   0    |     X      |    0     |  (d =)
	    ---------------------------------------------
	    | z   0     |   0    |     X      |    X     |  (d =) and (s =)
	    ---------------------------------------------
	    |    0     |   0    |     0      |    X     |  (s =)
	    ---------------------------------------------
	*/
	public PageReference doSearch() {
		System.debug('Doing the search');
		Boolean st = searchTerm.length() != 0;
		Boolean t = ptype.length() != 0;
		Boolean s = status.length() != 0;
		Boolean d = division.length() != 0;
		String sTerm = '%' + searchTerm + '%';
		
		if (!st && !t && !d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			];
		} else if (st && !t && !d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm];
		} else if (st && t && !d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm and Type__c = :ptype
			];
		} else if (st && !t && d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm and Hiring_Division__c = :division
			];
		} else if (st && t && d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c 
			Where Name Like :sTerm and Type__c = :ptype and Hiring_Division__c = :division
			];
		} else if (st && !t && !d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm and Status__c = :status
			];
		} else if (st && t && !d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm and Type__c = :ptype and Status__c = :status
			];
		} else if (st && t && d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm and Type__c = :ptype and Hiring_Division__c = :division and Status__c = :status
			];
		} else if (st && !t && d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Name Like :sTerm and Hiring_Division__c = :division and Status__c = :status
			];
		} else if (!st && t && !d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Type__c = :ptype];
		} else if (!st && t && d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Type__c = :ptype and Hiring_Division__c = :division];
		} else if (!st && t && !d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Type__c = :ptype and Status__c = :status];
		} else if (!st && t && d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Type__c = :ptype and Hiring_Division__c = :division and Status__c = :status];
		} else if (!st && !t && d && !s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Hiring_Division__c = :division];
		} else if (!st && !t && d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Hiring_Division__c = :division and Status__c = :status];
		} else if (!st && !t && !d && s) {
			positionList = [Select Id, Name, Max_Pay__c, User2__c, Hiring_Division__c, Type__c, User2__r.Name, Status__c From SFDC_Position__c
			Where Status__c = :status];
		}
		return null;
	}
	public List<SFDC_Position__c> getPositionList() {
		return positionList;
	}
				
				
				
				
				
				
}